<?php

namespace app\forms\item;

use app\forms\Model;
use app\helpers\MappingHelper;
use app\validators\PositiveInteger;

/**
 * 权限项 表单父类
 */
class BaseForm extends Model
{
    public $parentId;
    public $name;
    public $route;
    public $dataAuth;
    public $status;
    public $remark;

    public function rules()
    {
        return [
            ['parentId', PositiveInteger::class],
            ['parentId', 'default', 'value' => 0],

            ['name', 'trim'],
            ['name', 'string', 'length' => [2, 16]],
            ['name', 'required'],

            ['route', 'trim'],
            ['route', 'string', 'max' => 32],
            ['route', 'required'],

            ['dataAuth', 'integer'],
            ['dataAuth', 'in', 'range' => [0, 1]],
            ['dataAuth', 'default', 'value' => 0],

            ['status', 'integer'],
            ['status', 'in', 'range' => array_keys(MappingHelper::statusList())],
            ['status', 'default', 'value' => MappingHelper::STATUS_ACTIVE],

            ['remark', 'trim'],
            ['remark', 'string', 'max' => 64],
            ['remark', 'default', 'value' => ''],
        ];
    }
}